<?php
require_once('feed.php');
class google extends feed {
	var $xml;
	var $title;
	var $description;
	public function __construct($site,$products){
		parent::__construct($site,$products);
		
		$this->mapping=array(
							 'title'			=> 'name',
							 'g:condition'		=> 'condition',
							 'description'		=> 'description',
							 'g:id'				=> 'id',
							 'g:image_link'		=> 'image_url',
							 'link'				=> 'product_url',
							 'g:price'			=> 'price',
							 'g:quantity'		=> 'CUSTOM_100',
							 'g:weight'			=> 'weight',
							 'g:upc'			=> 'CUSTOM_432432'
							 );
		
		$this->title="Mobile Phones - China Mobile Phones";
		$this->description="China Wholesaler supplies Cheap Discount Mobile Phones";
		
	}
	
	public function toXml(){
	 		$this->xml = '<?xml version="1.0" encoding="UTF-8" ?>';
			$this->xml.=chr(13).'<rdf:RDF';
			$this->xml.=chr(13).'xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"';
			$this->xml.=chr(13).'xmlns="http://purl.org/rss/1.0/"';
			$this->xml.=chr(13).'xmlns:g="http://base.google.com/ns/1.0">';
			$this->xml.=chr(13);
			$this->xml.='<channel rdf:about="' .$this->site. '">';
			$this->xml.=chr(13).'<title>'.$this->title.'</title>';
			$this->xml.=chr(13).'<description>'.$this->description.'</description>';
			$this->xml.=chr(13).'<link>' .$this->site. '</link>';
			$this->xml.=chr(13).'<items>';
			$this->xml.=chr(13).'<rdf:Seq>';
			$this->xml.=chr(13);
			
			foreach ($this->data as $item) {
				$this->xml.= '<rdf:li resource="' .$item['product_url']. '"/>';
				$this->xml.= chr(13);
			}
			
			$this->xml.=chr(13).'</rdf:Seq>';
			$this->xml.=chr(13).'</items>';			
			$this->xml.=chr(13).'</channel>';
			
			$this->xml .= chr(13);
			
			foreach($this->data as $info){
			
			$this->xml.='<item rdf:about="'.$info["product_url"].'">';
			$this->xml .= "\r";
			foreach($this->mapping as $key=>$value){
					if(substr($value,0,6)!='CUSTOM'){
						$value=$info[$value];
						}
					else{
						$value=substr($value,7);
						if($key=='g:upc'){
							$value=rands('11');
							}
						}
						$this->xml.="<".$key.">";
						$this->xml.=str_replace("&","",$value);		
						$this->xml.="</".$key.">";
						$this->xml .= "\r";
				}
			$this->xml.='</item>';
			$this->xml .= chr(13);
		}
			$this->xml .='</rdf:RDF>';
			return $this->xml;
	}
	
}
?>